home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / exec / opendevice.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  3KB  |  124 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: opendevice.c,v 1.5 1996/10/24 15:50:53 aros Exp $
  4.     $Log: opendevice.c,v $
  5.     Revision 1.5  1996/10/24 15:50:53  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.4  1996/08/13 13:56:05  digulla
  9.     Replaced AROS_LA by AROS_LHA
  10.     Replaced some AROS_LH*I by AROS_LH*
  11.     Sorted and added includes
  12.  
  13.     Revision 1.3  1996/08/01 17:41:15  digulla
  14.     Added standard header for all files
  15.  
  16.     Desc:
  17.     Lang: english
  18. */
  19. #include <exec/execbase.h>
  20. #include <exec/devices.h>
  21. #include <exec/io.h>
  22. #include <exec/errors.h>
  23. #include <aros/libcall.h>
  24.  
  25. /*****************************************************************************
  26.  
  27.     NAME */
  28.     #include <exec/libraries.h>
  29.     #include <clib/exec_protos.h>
  30.  
  31.     AROS_LH4(BYTE, OpenDevice,
  32.  
  33. /*  SYNOPSIS */
  34.     AROS_LHA(STRPTR,             devName,    A0),
  35.     AROS_LHA(ULONG,              unitNumber, D0),
  36.     AROS_LHA(struct IORequest *, iORequest,  A1),
  37.     AROS_LHA(ULONG,              flags,      D1),
  38.  
  39. /*  LOCATION */
  40.     struct ExecBase *, SysBase, 74, Exec)
  41.  
  42. /*  FUNCTION
  43.     Tries to open a device and fill the iORequest structure.
  44.     And error is returned if this fails, 0 if all went well.
  45.  
  46.     INPUTS
  47.     devName    - Pointer to the devices's name.
  48.     unitNumber - The unit number. Most often 0.
  49.     iORequest  - Pointer do device specific information.
  50.              Will be filled out by the device.
  51.              Must lie in public (or at least shared) memory.
  52.     flags       - Some flags to give to the device.
  53.  
  54.     RESULT
  55.     Error code or 0 if all went well. The same value can be found
  56.     in the io_Error field.
  57.  
  58.     NOTES
  59.  
  60.     EXAMPLE
  61.  
  62.     BUGS
  63.  
  64.     SEE ALSO
  65.     CloseDevice()
  66.  
  67.     INTERNALS
  68.  
  69.     HISTORY
  70.  
  71. *****************************************************************************/
  72. {
  73.     AROS_LIBFUNC_INIT
  74.  
  75.     AROS_LIBBASE_EXT_DECL(struct ExecBase *,SysBase)
  76.     struct Device *device;
  77.     BYTE ret=IOERR_OPENFAIL;
  78.  
  79.     /* Arbitrate for the device list */
  80.     Forbid();
  81.  
  82.     /* Look for the device in our list */
  83.     device=(struct Device *)FindName(&SysBase->DeviceList,devName);
  84.  
  85.     /* Something found ? */
  86.     if(device!=NULL)
  87.     {
  88.     /* Init iorequest */
  89.     iORequest->io_Error=0;
  90.     iORequest->io_Device=device;
  91.     iORequest->io_Flags=flags;
  92.     iORequest->io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  93.  
  94.     /* Call Open vector. */
  95.     AROS_LVO_CALL3(void,
  96.         AROS_LCA(struct IORequest *,iORequest,A1),
  97.         AROS_LCA(ULONG,unitNumber,D0),
  98.         AROS_LCA(ULONG,flags,D1),
  99.         struct Device, device, 1,
  100.     );
  101.  
  102.     /* Check for error */
  103.     ret=iORequest->io_Error;
  104.     if(ret)
  105.         /* Mark request as non-open */
  106.         iORequest->io_Device=NULL;
  107.     }
  108.     /*
  109.     else
  110.     {
  111.     Under normal circumstances you'd expect the device loading here -
  112.     but this is only exec which doesn't know anything about the
  113.     filesystem level. Therefore dos.library has to SetFunction() this vector
  114.     for the additional functionality.
  115.     }
  116.     */
  117.  
  118.     /* All done. */
  119.     Permit();
  120.     return ret;
  121.     AROS_LIBFUNC_EXIT
  122. } /* OpenDevice */
  123.  
  124.